import * as _ from "@/utils/MyFun";
import * as TYPE from "../action-type";

let initialValue = {
  userInfo: {
    /*
     大致包含id，nickname，intro，website，avatar
     */
  },
};

const UserReducer = (state = initialValue, action) => {
  state = _.clone(state);
  switch (action.type) {
    case TYPE.USER_GETUSERINFO:
      state.userInfo = action.info;
      break;
    case TYPE.USER_LOGOUT:
      state.userInfo = {}; //恢复初始状态
      break;
    case TYPE.USER_SETUSERINFO:
      state.userInfo.data = {
        ...state.userInfo?.data,
        ...action.info,
      };
      break;
    default:
      //暂时为记录错误信息
      state = { ...state };
  }
  return state;
};

export default UserReducer;
